package com.ququ.syb.application.controller;

import com.ququ.common.result.Result;
import com.ququ.syb.application.service.ApplicationService;
import com.ququ.syb.common.pojo.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;


    @RequestMapping("/query")
    public Result<Application> getApplication(@RequestParam String appcode){
        return applicationService.getApplication(appcode);
    }

    @RequestMapping("/key")
    public Result<String> getApplicationKey(@RequestParam String appcode){
        return applicationService.getApplicationKey(appcode);
    }

    @RequestMapping("/list")
    public Result<List<Application>> listApplication(){
        return applicationService.listApplication();
    }

    @RequestMapping("/add")
    public Result<Application> addApplication(@RequestParam(required = false) String appcode,
                                              @RequestParam String appname,
                                              @RequestParam String homepage,
                                              @RequestParam(defaultValue = "1") Integer allowpay,
                                              @RequestParam(defaultValue = "1") Integer allowwithdraw){
        return applicationService.addApplication(appcode, appname, homepage, allowpay, allowwithdraw);
    }
}
